package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo15CoGroup {
  def main(args: Array[String]): Unit = {
    /**
     * cogroup:类似full outer join
     */
    val conf: SparkConf = new SparkConf()
    conf.setAppName("Demo15CoGroup")
    conf.setMaster("local")

    val sc: SparkContext = new SparkContext(conf)

    val kvRDD1: RDD[(String, Int)] = sc.parallelize(List(("k1", 1), ("k2", 2), ("k3", 3)))
    val kvRDD2: RDD[(String, Double)] = sc.parallelize(List(("k2", 2.2), ("k3", 3.3), ("k4", 4.4)))

    kvRDD1
      .cogroup(kvRDD2)
      .foreach(println)


  }

}
